home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevpcfb.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.3 KB  |  204 lines

  1. /* Copyright (C) 1989, 1995 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevpcfb.h,v 1.2 2000/09/19 19:00:15 lpd Exp $ */
  20. /* IBM PC frame buffer definitions */
  21.  
  22. #ifndef gdevpcfb_INCLUDED
  23. #  define gdevpcfb_INCLUDED
  24.  
  25. #ifdef __MSDOS__
  26. #  include "dos_.h"
  27. typedef union REGS registers;
  28.  
  29. #endif
  30.  
  31. /* For testing, the 16-color display may be defined as a monochrome, */
  32. /* 8-color, or 16-color device. */
  33. #define ega_bits_of_color 2    /* 0, 1, or 2 */
  34. #define rgb_max ega_bits_of_color
  35.  
  36. /* Define the short (integer) version of "transparent" color. */
  37. /* ****** Depends on gx_no_color_index being all 1's. ***** */
  38. #define no_color ((int)gx_no_color_index)
  39.  
  40. /* Procedures */
  41.  
  42.     /* See gxdevice.h for the definitions of the procedures. */
  43.  
  44. dev_proc_open_device(ega_open);
  45. dev_proc_close_device(ega_close);
  46. dev_proc_fill_rectangle(ega_fill_rectangle);
  47. dev_proc_tile_rectangle(ega_tile_rectangle);
  48. dev_proc_copy_mono(ega_copy_mono);
  49. dev_proc_copy_color(ega_copy_color);
  50. dev_proc_get_bits(ega_get_bits);
  51.  
  52. /* Structure for saving state of BIOS variables. */
  53. typedef struct pcfb_bios_state_s {
  54.     int display_mode;        /* must be first, see pcfb_save_state */
  55.     /* in gdevpcfb.c */
  56.     byte text_page;
  57.     uint text_cursor_mode;
  58.     uint text_font;
  59.     byte text_attribute;
  60.     byte border_color;
  61. } pcfb_bios_state;
  62.  
  63. /* Procedures used by gdevpcfb.c */
  64. void pcfb_set_signals(P1(gx_device *));
  65. void pcfb_get_state(P1(pcfb_bios_state *));
  66. void pcfb_set_mode(P1(int));
  67. void pcfb_set_state(P1(const pcfb_bios_state *));
  68.  
  69. /* Types for frame buffer pointers. */
  70. typedef byte *fb_ptr;
  71. typedef volatile byte *volatile_fb_ptr;
  72.  
  73. /* Define the nominal page height in inches. */
  74. #ifdef A4
  75. #  define PAGE_HEIGHT_INCHES 11.69
  76. #else
  77. #  define PAGE_HEIGHT_INCHES 11.0
  78. #endif
  79.  
  80. /* The device descriptor */
  81. typedef struct gx_device_ega_s gx_device_ega;
  82. struct gx_device_ega_s {
  83.     gx_device_common;
  84.     int raster;            /* frame buffer bytes per line */
  85.     int fb_seg_mult;        /* multiplier for segment part */
  86.     /* of frame buffer pointer */
  87.     int fb_byte_mult;        /* multiplier for word part ditto */
  88. #define mk_fb_ptr(x, y)\
  89.   (fb_dev->fb_byte_mult == 0 ?\
  90.    (fb_ptr)MK_PTR(regen + (y) * (fb_dev->fb_seg_mult), (x) >> 3) :\
  91.    (fb_ptr)MK_PTR(regen + ((y) >> 4) * (fb_dev->fb_seg_mult),\
  92.          (((y) & 15) * fb_dev->fb_byte_mult) + ((x) >> 3)))
  93.     int video_mode;
  94. };
  95.  
  96. /* Macro for creating instances */
  97. /* The initial parameters map an appropriate fraction of */
  98. /* the screen to a full-page coordinate space. */
  99. /* This may or may not be what is desired! */
  100. #define ega_device(dev_name, procs, fb_raster, screen_height, aspect_ratio, video_mode)\
  101.    {    std_device_dci_body(gx_device_ega, &procs, dev_name,\
  102.       fb_raster * 8, screen_height,\
  103.       (screen_height * (aspect_ratio)) / PAGE_HEIGHT_INCHES,    /* x dpi */\
  104.       screen_height / PAGE_HEIGHT_INCHES,        /* y dpi */\
  105.       (rgb_max ? 3 : 1),    /* num_components */\
  106.       4,            /* depth */\
  107.       (rgb_max ? rgb_max : 1),    /* max_gray */\
  108.       rgb_max,\
  109.       (rgb_max ? rgb_max + 1 : 2),    /* dither_grays */\
  110.       (rgb_max ? rgb_max + 1 : 0)    /* dither_colors */\
  111.     ),\
  112.      { 0 },            /* std_procs */\
  113.     fb_raster,\
  114.     (fb_raster & 15 ? fb_raster : fb_raster >> 4),\
  115.     (fb_raster & 15 ? fb_raster : 0),\
  116.     video_mode\
  117.    }
  118.  
  119. /* Define the device port and register numbers, and the regen map base */
  120. #define seq_addr 0x3c4
  121. #define s_map 2
  122. #define set_s_map(mask) outport2(seq_addr, s_map, mask)
  123. #define graph_addr 0x3ce
  124. #define g_const 0        /* set/reset */
  125. #define set_g_const(color) outport2(graph_addr, g_const, color)
  126. #define g_const_map 1        /* enable set/reset */
  127. #define set_g_const_map(map) outport2(graph_addr, g_const_map, map)
  128. #define g_function 3
  129. #  define gf_WRITE 0
  130. #  define gf_AND 8
  131. #  define gf_OR 0x10
  132. #  define gf_XOR 0x18
  133. #define set_g_function(func) outport2(graph_addr, g_function, func)
  134. #define g_read_plane 4
  135. #define set_g_read_plane(plane) outport2(graph_addr, g_read_plane, plane)
  136. #define g_mode 5
  137. #  define gm_DATA 0
  138. #  define gm_FILL 2
  139. #define set_g_mode(mode) outport2(graph_addr, g_mode, mode)
  140. #define g_mask 8
  141. #define set_g_mask(mask) outport2(graph_addr, g_mask, mask)
  142. #define select_g_mask() outportb(graph_addr, g_mask)
  143. #define out_g_mask(mask) outportb(graph_addr+1, mask)
  144. #define regen 0xa000
  145.  
  146. /* Define access to the frame buffer and the video registers */
  147. /* according to whether we are on a DOS system or a Unix system. */
  148.  
  149. #if defined(M_UNIX) || defined(M_XENIX) || defined(UNIX) || defined(SYSV) || defined(__linux__)
  150.  
  151.         /* SCO Unix/Xenix, AT&T SVR4, or Linux. */
  152.  
  153. #undef outportb
  154.  
  155. #if defined(__GNUC__)
  156.     /* Inline assembly version for gcc */
  157.     /* Under SCO, requires installing the gnu assembler as "as" */
  158. static inline void 
  159. outportb(int port, int data)
  160. {
  161.     __asm__ volatile ("outb %0,%1"::
  162.               "a"      ((unsigned char)data),
  163.               "d"      ((unsigned short)port));
  164. }
  165. static inline void 
  166. outport2(int port, int index, int data)
  167. {
  168.     __asm__ volatile ("movb %0,%%ah; movb %1,%%al; outw %%ax,%2"::
  169.               "qmi"    ((unsigned char)data),
  170.               "qmi"    ((unsigned char)index),
  171.               "d"      ((unsigned short)port):
  172.               "eax");
  173. }
  174. #else
  175. void outportb(P2(uint, byte));
  176. void outport2(P3(uint, byte, byte));
  177.  
  178. #endif
  179.  
  180. /* Redefine mk_fb_ptr -- no segmented addressing. */
  181.  
  182. #undef mk_fb_ptr
  183. extern fb_ptr fb_addr;
  184.  
  185. #define mk_fb_ptr(x, y)    (fb_addr + (y) * (fb_dev->raster) + ((x) >> 3))
  186.  
  187. #else
  188.  
  189.         /* MS-DOS */
  190.  
  191. /* outportb is defined in dos_.h */
  192. #define outport2(port, index, data)\
  193.   (outportb(port, index), outportb((port)+1, data))
  194.  
  195. #endif
  196.  
  197. /* Fetch and discard a byte.  Prevent the compiler from */
  198. /* optimizing this away. */
  199. static unsigned char byte_discard_;
  200.  
  201. #define byte_discard(expr) byte_discard_ = (expr)
  202.  
  203. #endif /* gdevpcfb_INCLUDED */
  204.